#树结构
#前序遍历，后序遍历，中序遍历，是根据根的位置确定的

#树变为二叉树，左儿女，右兄弟

#根据前序-中序，后序-中序确定二叉树，二叉树确定前序、中序、后序遍历


#二叉树类，定义
class Tree():
    def __init__(self,data,left=None,right=None):
        self.root=data
        self.left=left
        self.right=right

def pre_order(node):
    if not node:
        return 
    print(node.root)
    pre_order(node.left)
    pre_order(node.right)
        

tree0=Tree(0)
tree1=Tree(1)
tree2=Tree(2)
tree3=Tree(3)
tree4=Tree(4)
tree5=Tree(5)
tree6=Tree(6)
tree7=Tree(7)
tree8=Tree(8)
tree9=Tree(9)

tree0.left=tree1
tree0.right=tree2
tree1.left=tree3
tree1.right=tree4
tree2.left=tree5
tree2.right=tree6

pre_order(tree0)



def list_to_tree(li = None):
    if not li:
        return None
    t1=[]
    for i in li:
        if i is None:
            tl.append (None)
        else:
            tl.append (Tree(i))
    for idx in range ( len (li) / 2):
        if idx* 2 +1 < len (tl) and tl[idx* 2 + 1]:
            tl[idx].left = tl[idx* 2 +1]
        if idx*2 + 2 < len (tl) and tl[idx*2 + 2]:
            tl[ idx ].right = tl[ idx* 2 + 2]
        root = tl[0]
    return root


